import { contextBridge, ipcRenderer } from "electron";
import dialogipcRenderer from "./api/dialog/preloadingScript";
const electronApi = {
  ...dialogipcRenderer,
};

window.addEventListener("DOMContentLoaded", () => {
  // 示例：暴露版本信息到渲染进程
  const versions = process.versions;
  console.log("Electron versions:", versions);
});
// 暴露更新相关的API给渲染进程
contextBridge.exposeInMainWorld("electronUpdater", {
  // 检查更新
  checkForUpdates: () => ipcRenderer.send("check-for-updates"),
  // 立即安装更新
  installUpdateNow: () => ipcRenderer.send("install-update-now"),
  // 监听更新可用事件
  onUpdateAvailable: (callback) => ipcRenderer.on("update-available", (event, info) => callback(info)),
  // 监听下载进度事件
  onDownloadProgress: (callback) => ipcRenderer.on("download-progress", (event, progress) => callback(progress)),
  // 监听更新下载完成事件
  onUpdateDownloaded: (callback) => ipcRenderer.on("update-downloaded", (event, info) => callback(info)),
  // 监听更新错误事件
  onUpdateError: (callback) => ipcRenderer.on("update-error", (event, error) => callback(error)),
});
// // 向渲染进程暴露通信方法（挂载到 window.electronApi）
contextBridge.exposeInMainWorld("electronApi", electronApi);
